package org.soaring.btn;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;

import javax.swing.SwingConstants;

import org.come.Frame.ZhuFrame;
import org.come.Jpanel.CharacterMeridiansMainJpanel;
import org.come.bean.Meridians;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;

import com.tool.btn.MoBanBtn;
import com.tool.role.RoleData;

public class CharacterMeridiansBtn extends MoBanBtn {
	private int caozuo;
	private CharacterMeridiansMainJpanel characterMeridiansMainJpanel;

	public CharacterMeridiansBtn(String iconpath, int type, Color[] colors, Font font, String text, int caozuo,
								 CharacterMeridiansMainJpanel characterMeridiansMainJpanel) {
		super(iconpath, type, colors);
		setText(text);
		setFont(font);
		setVerticalTextPosition(SwingConstants.CENTER);
		setHorizontalTextPosition(SwingConstants.CENTER);
		this.caozuo = caozuo;
		this.characterMeridiansMainJpanel = characterMeridiansMainJpanel;
	}

	@Override
	public void chooseyes() {

	}

	@Override
	public void chooseno() {

	}

	@Override
	public void nochoose(MouseEvent e) {

		if (caozuo == 0) {
			// 重洗
			int chooseNum = characterMeridiansMainJpanel.getChooseNum();
			if (chooseNum == -1) {
				ZhuFrame.getZhuJpanel().addPrompt2("请先选择一个经脉");
				return;
			}
			String attr = characterMeridiansMainJpanel.getLockAttr().getIcon() == null ? "0" : "1";
			String quality = characterMeridiansMainJpanel.getLockQuality().getIcon() == null ? "0" : "1";
			SendMessageUntil.toServer(
					Agreement.getAgreement().rolechangeAgreement("X2" + (chooseNum + 1) + "_" + attr + "_" + quality));
		} else if (caozuo == 1) {
			Meridians m = characterMeridiansMainJpanel.getMeridians();

			if (characterMeridiansMainJpanel.getMoneyType() == 0) {

				characterMeridiansMainJpanel.setMoneyType(1);
				characterMeridiansMainJpanel.getBtnSeepUp().setText("仙玉修炼");
//				int m = characterMeridiansMainJpanel.getMeridians().getMoney();
				if (m != null) {
					characterMeridiansMainJpanel.setMoney(new BigDecimal(m.getMoney()));
				}

				characterMeridiansMainJpanel.getLabxianyu().setVisible(true);
				characterMeridiansMainJpanel.getLabxianyu()
						.setText(String.valueOf(RoleData.getRoleData().getLoginResult().getCodecard()));
			} else {
				characterMeridiansMainJpanel.setMoneyType(0);
				characterMeridiansMainJpanel.getBtnSeepUp().setText("金币修炼");
				if (m != null) {
//					int g = characterMeridiansMainJpanel.getMeridians().getGold();
					characterMeridiansMainJpanel.setMoney(new BigDecimal(m.getGold()));
				}
				characterMeridiansMainJpanel.getLabxianyu().setVisible(false);
			}
		} else if (caozuo == 2) {
			// 修炼
			int chooseNum = characterMeridiansMainJpanel.getChooseNum();
			if (chooseNum == -1) {
				ZhuFrame.getZhuJpanel().addPrompt2("请先选择一个经脉");
				return;
			}
			if (characterMeridiansMainJpanel.getMoneyType() == 0) {
				//金币
				SendMessageUntil.toServer(Agreement.getAgreement().rolechangeAgreement("X3" + (chooseNum + 1)));
			} else if (characterMeridiansMainJpanel.getMoneyType() == 1) {
				// 仙玉修炼已禁用
				ZhuFrame.getZhuJpanel().addPrompt2("仙玉修炼功能已关闭");
				// 或者如果需要完全移除选项，可以添加以下逻辑：
				// characterMeridiansMainJpanel.setMoneyType(0);
				// characterMeridiansMainJpanel.getBtnSeepUp().setText("金币修炼");
				// characterMeridiansMainJpanel.getLabxianyu().setVisible(false);
				// if (m != null) {
				//     characterMeridiansMainJpanel.setMoney(new BigDecimal(m.getGold()));
				// }
				return;
			}
		}

	}

}
